#include "capturerequest.h"
#include <QVector>
#include <QDateTime>

CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode, const QVariant &data) :
    m_mode(mode),
    m_data(data),
    m_forcedID(false),
    m_id(0)
{

}

void CaptureRequest::setStaticID(uint id)
{
    m_forcedID = true;
    m_id = id;
}

uint CaptureRequest::id() const
{
    if (m_forcedID) {
        return m_id;
    }

    uint id = 0;
    QVector<uint> v;
    v << qHash(m_mode) << qHash(QDateTime::currentMSecsSinceEpoch())
    << m_data.toInt();
    for (uint i : v) {
        id ^= i + 0x9e3779b9 + (id << 6) + (id >> 2);
    }
    return id;
}

CaptureRequest::CaptureMode CaptureRequest::captureMode() const
{
    return m_mode;
}

QVariant CaptureRequest::data() const
{
    return m_data;
}
